import chartConfig from "./chartConfig";

// 检验到期、超期未检 / 任务量、签收量、超期量趋势 / 隐患时间统计(本季度)
const getOverdue = (arrs) => {
  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      types: ["01", "02", "03", "04", "05"],
      data: [1, 6, 3, 4, 5],
    };
  }

  let deviceTrend = {
    tooltip: {
      trigger: "axis",
    },
    // legend: {
    //   data: ["锅炉", "压力容器", "电梯", "起重机械", "气瓶", "游乐设施"],
    //   textStyle: {
    //     color: chartConfig.c_font_color,
    //     fontSize: 14,
    //   },
    // },
    grid: {
      left: "3%",
      right: "5%",
      bottom: "3%",
      containLabel: true,
    },
    xAxis: {
      type: "category",
      boundaryGap: false,
      data: arrs.types,
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size,
      },
    },
    yAxis: {
      type: "value",
      nameTextStyle: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 2,
      },
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 2,
      },
    },
    series: [
      {
        name: "设备",
        type: "line",
        stack: "总量",
        data: arrs.data,
        label: {
          show: true,
          formatter: "{c}",
          color: "#67e0e3",
        },
        lineStyle: {
          color: "#67e0e3",
          width: 3,
        },
      },
    ],
  };
  return deviceTrend;
};

// 双折线
const getLineDouble = (arrs) => {
  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      types: ["01", "02", "03", "04", "05"],
      data1: {
        name: 'name1',
        arr: [1, 6, 3, 4, 5]
      },
      data2: {
        name: 'name2',
        arr: [3, 1, 6, 3, 4]
      },
    };
  }

  let deviceTrend = {
    tooltip: {
      trigger: "axis",
    },
    // legend: {
    //   data: ["锅炉", "压力容器", "电梯", "起重机械", "气瓶", "游乐设施"],
    //   textStyle: {
    //     color: chartConfig.c_font_color,
    //     fontSize: 14,
    //   },
    // },
    grid: {
      left: "3%",
      right: "5%",
      bottom: "3%",
      containLabel: true,
    },
    xAxis: {
      type: "category",
      boundaryGap: false,
      data: arrs.types,
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size,
      },
    },
    yAxis: {
      type: "value",
      nameTextStyle: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 2,
      },
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 2,
      },
    },
    series: [
      {
        name: arrs.data1.name,
        type: "line",
        stack: "总量",
        data: arrs.data1.arr,
        label: {
          show: true,
          formatter: "{c}",
          color: "#67e0e3",
        },
        lineStyle: {
          color: "#67e0e3",
          width: 3,
        },
      },
      {
        name: arrs.data2.name,
        type: "line",
        stack: "总量",
        data: arrs.data2.arr,
        label: {
          show: true,
          formatter: "{c}",
          color: "#67e0e3",
        },
        lineStyle: {
          color: "#67e0e3",
          width: 3,
        },
      },
    ],
  };
  return deviceTrend;
};

// 检验人员持证率
const getInspector = (arrs) => {
  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      types: ["-", "-", "-", "-", "-", "-"],
      data: [
        { value: 0, name: "-" },
        { value: 0, name: "-" },
        { value: 0, name: "-" },
        { value: 0, name: "-" },
        { value: 0, name: "-" },
        { value: 0, name: "-" },
      ],
    };
  }

  let ret = []
  for (let i = 0; i < arrs.types.length; i++) {
    const ele = arrs.types[i];
    ret[i] = {name:ele, value:arrs.data[i]}
  }
  arrs.data = ret

  let deviceStatus = {
    color: chartConfig.c_color_arr_6,
    tooltip: {
      trigger: "item",
      formatter: "{b}: {c} ({d}%)",
    },
    // legend: {
    //   orient: "vertical",
    //   right: 10,
    //   data: arrs.types,
    //   textStyle: {
    //     color: chartConfig.c_font_color,
    //     fontSize: chartConfig.c_font_size,
    //   },
    // },
    series: [
      {
        type: "pie",
        radius: ["20%", "80%"],
        avoidLabelOverlap: false,
        label: {
          show: true,
          position: "outside",
          fontSize: chartConfig.c_font_size,
          formatter: "{b}: {c}",
          color: chartConfig.c_font_color,
        },
        emphasis: {
          label: {
            show: true,
            fontSize: chartConfig.c_font_size + 2,
            fontWeight: "bold",
          },
        },
        labelLine: {
          show: false,
        },
        data: arrs.data,
      },
    ],
  };
  return deviceStatus;
};

// 隐患月份统计
const getHiddenMonth = (arrs) => {
  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      types: ["1月", "1月", "1月", "1月", "1月","1月", "1月", "1月", "1月", "1月","1月", "1月",],
      data: [1, 2, 3, 5, 4, 1, 2, 3, 5, 4, 1, 2,],
    };
  }

  let deviceYears = {
    grid: {
      top: "15%",
      left: "3%",
      right: "5%",
      bottom: "3%",
      containLabel: true,
    },
    xAxis: {
      type: "category",
      data: arrs.types,
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 2,
      },
    },
    yAxis: {
      type: "value",
      nameTextStyle: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 2,
      },
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 2,
      },
    },
    series: [
      {
        data: arrs.data,
        type: "bar",
        showBackground: true,
        backgroundStyle: {
          color: "rgba(220, 220, 220, 0.1)",
        },
        itemStyle: {
          normal: {
            color: function(params) {
              var colorlist = chartConfig.c_color_arr_3;
              return colorlist[params.dataIndex];
            },
            barBorderRadius: [5, 5, 0, 0],
          },
        },
        label: {
          show: true,
          formatter: "{c}",
          textStyle: {
            fontSize: chartConfig.c_font_size + 2,
          },
        },
      },
    ],
  };
  return deviceYears;
};

export { getOverdue, getInspector, getHiddenMonth, getLineDouble };
